package scanner.com.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.haha.extend.button.SwitchButton;

import scanner.com.preference.MyPreference;
import scanner.com.scanner.R;


/**
 * Created by longteng on 2016-6-7.
 */
public class SettingsActivity extends BaseActivity {

    SwitchButton soundSwitcher,vibrateSwitcher;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        findView();
        initView();
    }

    @Override
    protected void findView() {
        soundSwitcher = (SwitchButton) findViewById(R.id.sound_switcher);
        vibrateSwitcher = (SwitchButton) findViewById(R.id.vibrate_switcher);
    }

    @Override
    protected void initView() {
        soundSwitcher.setOnCheckChangeListener(onCheckChangeListener);
        vibrateSwitcher.setOnCheckChangeListener(onCheckChangeListener);
    }

    private SwitchButton.OnCheckChangeListener onCheckChangeListener = new SwitchButton.OnCheckChangeListener() {
        @Override
        public void OnCheck(SwitchButton switchButton, boolean isChecked) {
            switch(switchButton.getId()){
                case R.id.sound_switcher:
                    MyPreference.getInstance(SettingsActivity.this).setIsSoundOn(isChecked);
                    break;

                case R.id.vibrate_switcher:
                    MyPreference.getInstance(SettingsActivity.this).setIsVibrateOn(isChecked);
                    break;
            }
        }
    };
}
